<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta name="author" content="liguangdong">
		<title>积分比率制定</title>
		<script type="text/javascript" src="../script/common.js"></script>
		<script type="text/javascript">
		 
         var qt = {};				     //数据表格对象
	     var qt1={};
			//页面控件初始化
			function load() {
			Eui.showNavigation(); 	
				//Common.initDict(detview_save.grade, "customer_level", "全部");
				DWR.call('pointRateService.findPointRate',function(t){
				if(t)
				{
				 $('viewdate').bin.disabled=true;
				}
				else{
				 $('viewdate').bin.disabled=false;
				}
				
			});
				createTable();
				showData();
				setPages(["listview","gradeRulelist"]);
			}
		   function showData(){
                qt.showTable();
               }
     //生成表格，创建QueryTable对象   
		function createTable(){
			var columns =[];
			 columns[5]={title:"操作",width:"12%",align:"center",render:delect111,order:false};
			 columns[6]={title:"操作",width:"12%",align:"center",render:chFunc,order:false};
			 qt = new QueryTable("loy_pointRate1","viewdate","datalist",columns);
			 
		}
		function Cancel()
		{
		   switchPage("listview");
		   createTable();
		   showData();
		}
		function showData1()
		{
		  $("createDate2").value=formatEndDay($("createDate1").value);
		   createTable1();
		}
		function formatEndDay(str)
			{
			  if(str != "" && str != null){
		      var d = str.split("-");
		      d = new Date(new Number(d[0]),(new Number(d[1]) -1),new Number(d[2]) + 1);
		      d = new Date(d-1000);
		      return d.format("yyyy-MM-dd hh:mm:ss");
	            }
	            return "";	
			}
		function delect111(v,r)
	  {
	     if(r[1]=="初始态")
	     { 
	       return "<a href=# onclick=\"delectDetails('"+r[2]+"');return false;\">删除</a>"
	      }
	      else if(r[1]=="已停用态")
	      {
	       return "<a href=# onclick=\"delectDetails('"+r[2]+"');return false;\">删除</a>"
	      }
	      else
	      {
	         return "<a href=# onclick=\><font color=\"gray\">删除</font></a>"
	      }
	  }
	  //search方法主要是查找数据库中有没有'初始化'状态的信息
	  function search()
	  {
	   DWR.call('pointRateService.findPointRate',function(t){
				if(t)
				{
				 $('viewdate').bin.disabled=true;
				}
				else{
				 $('viewdate').bin.disabled=false;
				}
				
			});
	  }
	  function delectDetails(id)
	  {  
	    if(showQuestion("您确认删除此积分比率?")==false){
			
				return;
			}
			DWR.call('pointRateService.deletePointRate',id,function(t){
			     search();
				 showData() ;
			});
	  }
		function createTable1()
		{
		     var columns =[];
			 // columns[5]={title:"操作",width:"12%",align:"center",render:delect,order:false};
			 //columns[6]={title:"操作",width:"12%",align:"center",render:chFunc,order:false};
			 qt1 = new QueryTable("loy_pointRateAll","gradeRulelistform","gradelist111",columns);
			 qt1.showTable();
			 
		}
	  function delect(v,r)
	  {
	     if(r[1]=="初始态")
	     { 
	       return "<a href=# onclick=\"delectDetails111('"+r[2]+"');return false;\">删除</a>"
	      }
	      else if(r[1]=="已停用态")
	      {
	       return "<a href=# onclick=\"delectDetails111('"+r[2]+"');return false;\">删除</a>"
	      }
	      else
	      {
	         return "<a href=# onclick=\><font color=\"gray\">删除</font></a>"
	      }
	  }
	  function delectDetails111(id)
	  {  
	    if(showQuestion("您确认删除此积分比率?")==false){
			
				return;
			}
			DWR.call('pointRateService.deletePointRate',id,function(t){
				 showData1() ;
			});
	  }
	  function chFunc(v,r){
	  
	    if(r[1]=="初始态")
	    {
	     return	"<a href=# onclick=\"check('"+r[2]+"');return false;\">审核</a>"
	    }
	     
	     else return "<a href=# ><font color=\"gray\">审核</font></a>"
    }
    function check(id){  
    
       if(showQuestion("您确认要审核?")==false){
			
				return;
			}
        DWR.call('pointRateService.pointRateCheck',id,function(){
        createTable();
         search();
	    showData();
	    switchPage('listview');
   	 });
	}
       function save(){	
		   if(!checkForm("viewdate"))return;
		   var rate11=$("viewdate").rate.value;
		   
		   if(Number(rate11)<=0)
		   {
		     showQuestion("积分比率必须大于0");
		     return;
		   }
	       var rateReal=$("viewdate").rate.value;
		   rateReal = Format.yuanToFen(rateReal);
	      	
	       DWR.call('pointRateService.createPointRate',rateReal,function(t){
	       
	       	
	           
				 createTable();
				 DWR.call('pointRateService.findPointRate',function(t){
				if(t)
				{
				 $('viewdate').bin.disabled=true;
				}
				else{
				 $('viewdate').bin.disabled=false;
				}
				
			});
				 showData();
			});	
		}
		function history(){
		  switchPage("gradeRulelist");
		}
			
		</script>
	</head>
	
	
<body onload="load()">
<!--页面导航-->
<div class=" nav ">
<div id="nav">&nbsp;</div>
</div>
<div id="content"><!--查询静态页面部分-->
<div id=listview>
<div class="formTitle">积分比率制定</div>
<div class="form">
<form name="viewdate" id="viewdate">
<div class="setForm">
<table cellSpacing="0" cellPadding="4" width="100%" border="0" class="label5">
	<tr>
		<td><label>积分比率</label><input type="text" id="rate" name="rate" onBlur="checkV(this,'double')">元(RMB)/积分</td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td><button type="button" id='bin' onclick="save()">保 存</button><button type="button" onclick="history()">查看历史记录</button></td>
	</tr>
</table>
</div>
</form>
</div>
<div id=datalist></div>
</div>
</div>

 <div id="gradeRulelist" style="display:none;">
			<div class="form">
				<form id="gradeRulelistform" name="listform1" action="">
					<table cellSpacing=0 cellPadding=4 width="100%" border=0 class="col2 label6">
					  	<tr>
		                  <td><label>制定日期</label> <input type="text"
						          name="createDate1" id="createDate1" onBlur="checkV(this,'date')"><img align='absMiddle' onmouseup='showDatePicker("createDate1" );' src="../images/icon/date.gif" alt="选择日期" style="CURSOR: hand" border="0">
						</td>
						<td>
						  <button type="button" onclick="showData1()">查 询</button><button type="button" onclick="Cancel()">返 回</button>
						</td>
						<td> <input type="hidden"  name="createDate2" id="createDate2 " /> </td>
	                    </tr>
					 </table>
				</form>	 
			</div>
			<div id="gradelist111"></div>	
		</div>

</html>